package storage

import (
	"IrisStandard/config"
	"IrisStandard/util"
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
	"xorm.io/core"
)

var (
	Mysql *xorm.Engine
)

func init() {
	//连接数据库
	url := config.Setting.Mysql.Username + ":" + config.Setting.Mysql.Password + "@tcp(" + config.Setting.Mysql.Host + ":" + config.Setting.Mysql.Port + ")/" + config.Setting.Mysql.DbName + "?" + config.Setting.Mysql.Parameter
	engine, err := xorm.NewEngine("mysql", url)
	util.FailOnException("An error occurred while connecting to Mysql", err)
	// 设置表名映射
	tableMapper := core.NewPrefixMapper(core.SnakeMapper{}, config.Setting.Mysql.TablePrefix)
	engine.SetTableMapper(tableMapper)
	//engine.TZLocation, _ = time.LoadLocation("Asia/Shanghai")
	Mysql = engine
}